using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;


namespace BasicallyNot.CodeTransformers
{

	#region Adornment Factory

	/// <summary>
	/// Establishes an <see cref="IAdornmentLayer"/> to place the adornment on and exports the <see cref="IWpfTextViewCreationListener"/>
	/// that instantiates the adornment on the event of a <see cref="IWpfTextView"/>'s creation
	/// </summary>
	[Export( typeof( IWpfTextViewCreationListener ) )]
	[ContentType( "Basic" )]
	[TextViewRole( PredefinedTextViewRoles.Document )]
	internal sealed class CodeTransformerFactory : IWpfTextViewCreationListener
	{

		/// <summary>
		/// Allows us to fetch classification info from Visual Studio Options,
		/// such as font styling and coloring for plain text, etc.
		/// </summary>
		[Import]
		private IEditorFormatMapService EditorFormatMapService { get; set; }

		/// <summary>
		/// Defines the adornment layer for the adornment. This layer is ordered 
		/// after the text layer in the Z-order
		/// </summary>
		[Export( typeof( AdornmentLayerDefinition ) )]
		[Name( "CodeTransformerManager" )]
		[Order( After = PredefinedAdornmentLayers.Text, Before = PredefinedAdornmentLayers.Caret )]
		[TextViewRole( PredefinedTextViewRoles.Document )]
		public AdornmentLayerDefinition editorAdornmentLayer = null;

		/// <summary>
		/// Instantiates a KeywordTransformerManager when a textView is created.
		/// </summary>
		/// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
		public void TextViewCreated( IWpfTextView textView )
		{
			new CodeTransformerManager( textView, EditorFormatMapService.GetEditorFormatMap( textView ) );
		}

	}

	#endregion // Adornment Factory

}
